package constant.milk.cashbook.insert;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class AssetChoiceActivity extends SuperActivity
{
	public static final String ASSET_CHOICE_DATA = "ASSET_CHOICE_DATA";

	public static final String INSERT_TYPE = "INSERT_TYPE";
	
	public static final int OUT = 0;
	public static final int IN = 1;
	public static final int GIFTCARD = 2;
	public static final int RESULT = 3;
	
	private View realView;
	private View bankView;
	private View checkCardView;
	private View creditCardView;
	private View phoneView;
	private View giftCardView;
	
	private RadioButton realRadio;
	private RadioButton bankRadio;
	private RadioButton checkCardRadio;
	private RadioButton creditCardRadio;
	private RadioButton phoneRadio;
	private RadioButton giftCardRadio;
	
	private Button checkButton;
	
	private String assetStr;
	
	private int flag;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.asset_choice_activity);
		
		setTitle("자산선택");
		
		setGoneTipButton();
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		realView = findViewById(R.id.insertAssetRealView);
		bankView = findViewById(R.id.insertAssetBankView);
		checkCardView = findViewById(R.id.insertAssetCheckCardView);
		creditCardView = findViewById(R.id.insertAssetCreditCardView);
		phoneView = findViewById(R.id.insertAssetPhoneView);
		giftCardView = findViewById(R.id.insertAssetGiftCardView);
		
		realRadio = (RadioButton) findViewById(R.id.insertAssetRealRadio);
		bankRadio = (RadioButton) findViewById(R.id.insertAssetBankRadio);
		checkCardRadio = (RadioButton) findViewById(R.id.insertAssetCheckCardRadio);
		creditCardRadio = (RadioButton) findViewById(R.id.insertAssetCreditCardRadio);
		phoneRadio = (RadioButton) findViewById(R.id.insertAssetPhoneRadio);
		giftCardRadio = (RadioButton) findViewById(R.id.insertAssetGiftCardRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		realView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRealRadio();
			}
		});
		
		bankView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setBankRadio();
			}
		});
		
		checkCardView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setCheckCardRadio();
			}
		});
		
		creditCardView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setCreditRadio();
			}
		});
		
		phoneView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setPhoneRadio();
			}
		});
		
		giftCardView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setGiftCardRadio();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(ASSET_CHOICE_DATA, assetStr);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
		
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String data = intent.getStringExtra(ASSET_CHOICE_DATA);
		flag = intent.getIntExtra(INSERT_TYPE, 0);
		
		if (data.equals(getResources().getString(R.string.realAsset)))
		{
			setRealRadio();
		}
		else if (data.equals(getResources().getString(R.string.bankAsset)))
		{
			setBankRadio();
		}
		else if (data.equals(getResources().getString(R.string.checkCardAsset)))
		{
			setCheckCardRadio();
		}
		else if (data.equals(getResources().getString(R.string.creditCardAsset)))
		{
			setCreditRadio();
		}
		else if (data.equals(getResources().getString(R.string.phoneAsset)))
		{
			setPhoneRadio();
		}
		else if (data.equals(getResources().getString(R.string.giftCardAsset)))
		{
			setGiftCardRadio();
		}
		
		if (flag == OUT)
		{
			creditCardView.setVisibility(View.VISIBLE);
			phoneView.setVisibility(View.VISIBLE);
		}
		else if (flag == IN)
		{
			creditCardView.setVisibility(View.GONE);
			phoneView.setVisibility(View.GONE);
		}
		else if (flag == GIFTCARD)
		{
			phoneView.setVisibility(View.GONE);
		}
		else if (flag == RESULT)
		{
			realView.setVisibility(View.GONE);
			bankView.setVisibility(View.VISIBLE);
			checkCardView.setVisibility(View.GONE);
			creditCardView.setVisibility(View.VISIBLE);
			phoneView.setVisibility(View.GONE);
		}
		
		giftCardView.setVisibility(View.GONE);
	}
	
	private void setRealRadio()
	{
		realRadio.setChecked(true);
		bankRadio.setChecked(false);
		checkCardRadio.setChecked(false);
		creditCardRadio.setChecked(false);
		phoneRadio.setChecked(false);
		giftCardRadio.setChecked(false);
		assetStr = getResources().getString(R.string.realAsset);
	}
	
	private void setBankRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(true);
		checkCardRadio.setChecked(false);
		creditCardRadio.setChecked(false);
		phoneRadio.setChecked(false);
		giftCardRadio.setChecked(false);
		assetStr = getResources().getString(R.string.bankAsset);
	}
	
	private void setCheckCardRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkCardRadio.setChecked(true);
		creditCardRadio.setChecked(false);
		phoneRadio.setChecked(false);
		giftCardRadio.setChecked(false);
		assetStr = getResources().getString(R.string.checkCardAsset);
	}
	
	private void setCreditRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkCardRadio.setChecked(false);
		creditCardRadio.setChecked(true);
		phoneRadio.setChecked(false);
		giftCardRadio.setChecked(false);
		assetStr = getResources().getString(R.string.creditCardAsset);
	}
	
	private void setPhoneRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkCardRadio.setChecked(false);
		creditCardRadio.setChecked(false);
		phoneRadio.setChecked(true);
		giftCardRadio.setChecked(false);
		assetStr = getResources().getString(R.string.phoneAsset);
	}
	
	private void setGiftCardRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkCardRadio.setChecked(false);
		creditCardRadio.setChecked(false);
		phoneRadio.setChecked(false);
		giftCardRadio.setChecked(true);
		assetStr = getResources().getString(R.string.giftCardAsset);
	}
	
	@Override
	protected void tipButton()
	{
	}
}
